# Maintainer: Diego Sogari <diego.sogari@gmail.com>

_realname=googletest
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=r932.0a43962
pkgrel=1
pkgdesc="Google Test (mingw-w64)"
arch=('any')
url="https://github.com/google/googletest"
license=('custom:BSD3')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-cmake")
source=("${_realname}::git+https://github.com/google/googletest.git"
        "${_realname}-0a43962.patch")
sha256sums=('SKIP'
            'a5d2f58a794b5cb99121a8b2ce2d98ac7e46e955653d78a4c9757b9783d1fe21')

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd "${srcdir}/${_realname}"
  patch -Np1 -i "../${_realname}-0a43962.patch"
}

build() {
  rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_SHARED_LIBS=ON \
    -Dgtest_disable_pthreads=YES \
    -Dgtest_build_tests=YES \
    -Dgmock_build_tests=YES \
    -Dgtest_build_samples=YES \
    "../${_realname}"

  make
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make test
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
